package com.slfx.idgen.demo.idgen.config;

import com.slfx.idgen.demo.idgen.datetime.DatetimeIdServer;
import com.slfx.idgen.demo.idgen.snowflake.IdWorker;
import com.slfx.idgen.demo.idgen.datetime.DatetimeIdProperties;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@AutoConfigureAfter(IdWorkerConfiguration.class)
@Import({IdWorkerConfiguration.class})
@EnableConfigurationProperties({DatetimeIdProperties.class})
public class DatetimeIdServerAutoConfiguration {

    private DatetimeIdProperties datetimeIdProperties;

    public DatetimeIdServerAutoConfiguration(DatetimeIdProperties datetimeIdProperties ) {
        this.datetimeIdProperties = datetimeIdProperties;
    }

    @Bean("datetimeIdServer")
    public DatetimeIdServer initDatetimeId(IdWorker idWorker) {
        return new DatetimeIdServer(idWorker, datetimeIdProperties.getMaxSequenceBits());
    }
}
